<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="e" uri="/easytogo-tags"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>新用户组</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<e:base/>   
	<script type="text/javascript">
		window.onload = function(){
			var roleIds = "${roleIds}".split(",");
			for(i=0;i<roleIds.length;i++){
        		$("input[type='checkbox'][value='"+roleIds[i]+"']").attr("checked","checked");
        	}
		}
        function sub_new(){
			var id=$("#id").val();
			var roleIds = "";
			$("input[type=checkbox][checked]").each(function(){
				roleIds=roleIds+","+$(this).val(); 
			});
			if(roleIds!=""){
				roleIds = roleIds.substr(1);
			}
			var url="${pageContext.request.contextPath}/admin/usergroup_saveNew.action";
			if(id!=null&&id!=""){//如果有id说明是更新
				var url="${pageContext.request.contextPath}/admin/usergroup_saveUpdate.action";
			}
			$.ajax({
				type: "post",
				url: url,
				data: {"id":id,"name":$("#name").val(),"roleIds":roleIds},
				dataType:"html",
				success: function(msg){
			  		if(msg=="failed"){
						alert("保存失败!");
					}else{
						if("${successAlert}"=="1"){
							alert("保存成功!");
						}
						parent.afterSave();
					}
				}
			}); 
		}
    </script>
  </head>
  
  <body>
	   <table height="100%">
	    	<tr>
	    		<td>名称</td>
	    		<td>
	    			<input id="name" name="name" type="text" value="${name}"/>
	    			<input id="id" name="id" type="hidden" value="${id}"/>
	    		</td>
	    	</tr>
	    	<tr height="100%">
	    		<td>角色</td>
	    		<td height="100%">
	    			 <div style="height: 100%;width: 100%;float: left;overflow: auto;">
						  <table border="1">
							  <s:iterator value="roleList" var="r">
							  	<tr><td><s:if test="admin==1">后台</s:if><s:else>前台</s:else></td><td>${name}</td><td><input type="checkbox" name="roleIds" value="${id}"/></td></tr>
							  </s:iterator>
						  </table>
					  </div>
	    		</td>
	    	</tr>
	    	<tr>
	    		<td colspan="2" align="center"><input type="button" value="提交" onclick="sub_new();"/></td>
	    	</tr>
	    </table>
  </body>
</html>
